<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Basic Layout - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="css/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="css/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="css/mycss.css"/>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="js/util.js"></script>
</head>
<body>
<table id="weixin_msg_prs_table"></table>
<script type="text/javascript">
    var $weixin_msg_prs_table=$('#weixin_msg_prs_table');
    $weixin_msg_prs_table.datagrid({
        url:'msgprs/list.json',
        saveUrl:'msgprs/api?method=add',
       	editUrl:'msgprs/api?method=update',
       	delUrl:'msgprs/api?method=del',
        columns: [
            [
                {field:'ck',checkbox:true},
                {field: 'id', title: 'RoleId'},
                {field: 'name', title: '名称',width:100,editor: {type: 'textbox', options: {required: true}}},
                {field: 'retype', title: '返回类型',width:100,
                	formatter:function(value){
                		return msglist[value];
                	},
                	editor: {type: 'combobox', options: {required: true,valueField: 'value',
                    textField: 'label',
                    data:msglist.getData()
                    }}},
                {field: 'msgId', title: '消息id(固定返回消息)(可为空)',editor: {type: 'numberspinner',options:{min:0}}},
                {field: 'stime', title: '开始时间', 
                	formatter:function(value,rowData){
                		if(value){
                			if(typeof(value)=='number')return new Date(value).toLocaleString();
                    		rowData.stime=new Date(value).getTime();
                    		return value;
                		}
                		
                	},width: 180,editor: {type: 'datetimebox', options: {
                		required: true,
                		parser:function(s){
                			if(s){
                				return new Date(s);
                			}
                			return new Date();
                		}
                	}}},
                {field: 'endtime', title: '结束时间',
                		formatter:function(value,rowData){
                			if(value){
                    			if(typeof(value)=='number')return new Date(value).toLocaleString();
                        		rowData.endtime=new Date(value).getTime();
                        		return value;
                    		}
                    	}, width: 180,editor: {type: 'datetimebox', options: {
                    		parser:function(s){
                    			if(s){
                    				return new Date(s);
                    			}
                    			return new Date();
                    		}
                    	}}},
                {field: 'plugin', title: '对应插件', width: 180,editor: {type: 'textbox'}},
                {field: 'enable', title: '是否启用插件', width: 80,editor: {type: 'checkbox', options: {on: 'true', off: 'false'}}}
                /*{field: 'btn', title: '操作', formatter: function () {
                 return btn2;
                 }}*/
            ]
        ],
        onBeforeEdit:function(rowIndex){
            var a = $weixin_msg_prs_table.datagrid('options');
            a.edititem.push(rowIndex);
        },
        onDblClickRow:function(rowIndex){
            $weixin_msg_prs_table.datagrid('beginEdit', rowIndex);
        },
        toolbar:[
            {
                iconCls:'icon-add',
                text:'添加',
                handler:function(){
                	$weixin_msg_prs_table.datagrid('addRow',{
                		endtime:978278400000,
                		name:'sss'
                	});
                }
            },
            {
                iconCls: 'icon-save',
                text:'接受保存',
                handler:function(){
                	$weixin_msg_prs_table.datagrid('RecChange');
                }
            },
            {
                iconCls:'icon-save',
                text:'保存',
                handler:function(){
                	$weixin_msg_prs_table.datagrid('SaveData');
                }
            },
            {
                iconCls:'icon-cancel',
                text:'取消更改',
                handler:function(){
					$weixin_msg_prs_table.datagrid('CancelEdit');
                }
            },
            {
                iconCls:'icon-remove',
                text:'删除(默认的规则无法删除只能更改)',
                handler:function(){
                	$weixin_msg_prs_table.datagrid('DelRows');
                }
            },
            {
            	iconCls:'icon-save',
            	text:'初始化消息回复规则(修改过后并不是立即生效，需要重新初始化)',
            	handler:function(){
            		$.get('initmsg',undefined,function(data){
						if(data.success){
							showMsg(0, '消息规则初始化成功');
						}
					},'json');
            	}
            }
        ]
    });
</script>
</body>
</html>